<template>
    <h2>注册页面</h2>
    <table class="table table-bordered"  border="1" cellpadding="0" cellspacing="0" width="250" align="center">
        <tr>
            <td>用户名</td>
            <td><input type="text" v-model="info.uname"></td>
        </tr>
        <tr>
            <td>密码</td>
            <td><input type="password" v-model="info.upwd"></td>
        </tr>
        <tr>
            <td colspan="2"><input type="button" value="注册" @click="logins"></td>
        </tr>
    </table>
   
</template>
<script setup lang="ts">
import {ref} from 'vue'
import {useRouter} from 'vue-router'
import axios from 'axios'
const info=ref({
    uname:"",
    upwd:""
})
const router=useRouter()

const logins=()=>{
    if(info.value.uname==""){
alert('用户名不能为空')
return
    }
    if(info.value.upwd==""){
        alert('用户密码不能为空')
        return
    }
    if(info.value.upwd.length<6||info.value.upwd.length>30)
    {
        alert('用户密码长度不得小于6位并且不得超过30位')
        return
    }
    
    axios({
        url:"https://localhost:44394/api/UserLoginController/Logian",
        method:"post",
        data:{
            UName:info.value.uname,
            UPwd:info.value.upwd
        }
    })
    .then(res=>{
        if(res.data==-1){
            alert('用户名已经存在')
            return
        }
        if(res.data>0){
            alert('用户注册成功')
            router.push('/usershow')
        }else{
            router.push('/usershow')
        }
    })
}
</script>
